package com.sykj.servies.impl;

import com.sykj.dao.CategoryDao;
import com.sykj.pojo.Category;
import com.sykj.servies.CategoryServies;
import com.sykj.servies.ProductServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiesImpl implements CategoryServies{
    //商品分类
    @Autowired
    CategoryDao categoryDao;
    //商品列表
    @Autowired
    ProductServies productServies;

    @Override
    public List list() {
    //查询所有分类，放在集合中
        List<Category> categoryList=categoryDao.selectByExample(null);
        return categoryList;
    }

    //增加分类
    @Override
    public void save(Category category) {
        categoryDao.insert(category);

    }


    //删除，如果该分类下有商品，那就不能删除
    @Override
    public void del(int id) {
//        boolean cunzai=productServies.findProByCid(id);
        //如果没有就删除
//        if (!cunzai){
            categoryDao.deleteByPrimaryKey(id);
//        }
    }
    //得到单个分类的id
    @Override
    public Category get(int id) {
        return categoryDao.selectByPrimaryKey(id);
    }

    //修改
    @Override
    public void update(Category category) {

        categoryDao.updateByPrimaryKeySelective(category);
    }


}
